#!/bin/bash
#plugin for pMusic
#NAME: Backend command
#INFO: Show the playing command and the output from the pMusic backend.

#Copyright 2013,2016 - GPL
#Sigmund Berglund - Valåmoen, Norway.

#Version 0.2 - Jan 2016

export TEXTDOMAIN=pmusic
export OUTPUT_CHARSET=UTF-8
export WORKDIR=$HOME/.pmusic/tmp
export APPDIR=${0%/*}; APPDIR=${APPDIR%/*}

#gtk-theme
echo 'style "black_mono" { font_name="Mono" base[NORMAL]="black" text[NORMAL]="green" }
widget "*backend_cmd" style "black_mono"
style "mono" { font_name="Mono" base[NORMAL]="grey10" text[NORMAL]="white" }
widget "*output*" style "mono"' > $WORKDIR/gtkrc
export GTK2_RC_FILES=$WORKDIR/gtkrc:/root/.gtkrc-2.0 #include theme stuff with system themes


echo '
<window icon-name="pmusic" title="pMusic - '$(gettext 'Backend info')'" default_height="600" default_width="700">
<vbox space-expand="true" space-fill="true">
  <vbox space-expand="false" space-fill="false">
  <hbox homogeneous="true">
    <togglebutton space-expand="true" space-fill="true">
      <label>'$(gettext 'Backend commands')'</label>
      <input>echo true</input>
      <action>if true show:VBOX_CMD</action>
      <action>if false hide:VBOX_CMD</action>
    </togglebutton>
    <text space-expand="true" space-fill="true"><label>""</label></text>
    <text space-expand="true" space-fill="true"><label>""</label></text>
  </hbox>
  </vbox>
  <vbox margin="20" space-expand="true" space-fill="true">
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="false" space-fill="false">
        <vbox space-expand="true" space-fill="true">
          <button space-expand="false" space-fill="false">
            <input file stock="gtk-edit"></input>
            <action>'$TEXT_EDITOR' '$WORKDIR'/exec &</action>
          </button>
          <text angle="90" wrap="false" yalign="0" space-expand="true" space-fill="true"><label>'$(gettext 'Playback')'</label></text>
        </vbox>
      </hbox>
      <edit name="backend_cmd" editable="false" left_margin="10" wrap-mode="1">
        <variable>CMD</variable>
        <input file>'$WORKDIR'/exec</input>
      </edit>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="false" space-fill="false">
        <vbox space-expand="true" space-fill="true">
          <button space-expand="false" space-fill="false">
            <input file stock="gtk-edit"></input>
            <action>'$TEXT_EDITOR' '$WORKDIR'/exec_copy &</action>
          </button>
          <text angle="90" wrap="false" yalign="0" space-expand="true" space-fill="true"><label>'$(gettext 'Export')'</label></text>
        </vbox>
      </hbox>
      <edit name="backend_cmd" editable="false" left_margin="10" wrap-mode="1">
        <variable>CMD_COPY</variable>
        <input file>'$WORKDIR'/exec_copy</input>
      </edit>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="false" space-fill="false">
        <vbox space-expand="true" space-fill="true">
          <button space-expand="false" space-fill="false">
            <input file stock="gtk-edit"></input>
            <action>'$TEXT_EDITOR' '$WORKDIR'/visualization_exec &</action>
          </button>
          <text angle="90" wrap="false" yalign="0" space-expand="true" space-fill="true"><label>'$(gettext 'Visualization')'</label></text>
        </vbox>
      </hbox>
      <edit name="backend_cmd" editable="false" left_margin="10" wrap-mode="1">
        <variable>CMD_VISUALIZATION</variable>
        <input file>'$WORKDIR'/visualization_exec</input>
      </edit>
    </hbox>
    <variable>VBOX_CMD</variable>
  </vbox>

  <vbox space-expand="false" space-fill="false">
  <hbox homogeneous="true">
    <togglebutton space-expand="true" space-fill="true">
      <label>'$(gettext 'Output of ffmpeg')'</label>
      <action>if true show:VBOX_FFMPEG_OUT</action>
      <action>if false hide:VBOX_FFMPEG_OUT</action>
    </togglebutton>
    <text space-expand="true" space-fill="true"><label>""</label></text>
    <text space-expand="true" space-fill="true"><label>""</label></text>
  </hbox>
  </vbox>
  <hbox visible="false" margin="20" space-expand="true" space-fill="true">
    <hbox space-expand="false" space-fill="false">
      <vbox space-expand="true" space-fill="true">
        <button space-expand="false" space-fill="false">
          <input file stock="gtk-edit"></input>
          <action>'$TEXT_EDITOR' '$WORKDIR'/ffmpeg_output &</action>
        </button>
      </vbox>
    </hbox>
    <edit name="ffmpeg_output" editable="false" left_margin="10" wrap-mode="1">
      <variable>FFMPEG_OUT</variable>
      <input file>'$WORKDIR'/ffmpeg_output</input>
    </edit>
    <variable>VBOX_FFMPEG_OUT</variable>
  </hbox>

  <vbox space-expand="false" space-fill="false">
  <hbox homogeneous="true">
    <togglebutton space-expand="true" space-fill="true">
      <label>'$(gettext 'Output of aplay (alsa)')'</label>
      <action>if true show:VBOX_APLAY_OUT</action>
      <action>if false hide:VBOX_APLAY_OUT</action>
    </togglebutton>
    <text space-expand="true" space-fill="true"><label>""</label></text>
    <text space-expand="true" space-fill="true"><label>""</label></text>
  </hbox>
  </vbox>
  <hbox visible="false" margin="20" space-expand="true" space-fill="true">
    <hbox space-expand="false" space-fill="false">
      <vbox space-expand="true" space-fill="true">
        <button space-expand="false" space-fill="false">
          <input file stock="gtk-edit"></input>
          <action>'$TEXT_EDITOR' '$WORKDIR'/aplay_error &</action>
        </button>
      </vbox>
    </hbox>
    <edit name="aplay_output" editable="false" left_margin="10" wrap-mode="1">
      <variable>APLAY_OUT</variable>
      <input file>'$WORKDIR'/aplay_error</input>
    </edit>
    <variable>VBOX_APLAY_OUT</variable>
  </hbox>

  <vbox space-expand="false" space-fill="false">
  <hbox homogeneous="true">
    <togglebutton space-expand="true" space-fill="true">
      <label>'$(gettext 'Debug log')'</label>
      <action>if true show:VBOX_DEBUG</action>
      <action>if false hide:VBOX_DEBUG</action>
    </togglebutton>
    <text space-expand="true" space-fill="true"><label>""</label></text>
    <text space-expand="true" space-fill="true"><label>""</label></text>
  </hbox>
  </vbox>
  <hbox visible="false" margin="20" space-expand="true" space-fill="true">
    <hbox space-expand="false" space-fill="false">
      <vbox space-expand="true" space-fill="true">
        <button space-expand="false" space-fill="false">
          <input file stock="gtk-edit"></input>
          <action>'$TEXT_EDITOR' '$WORKDIR'/stderr &</action>
        </button>
      </vbox>
    </hbox>
    <edit name="debug_output" editable="false" left_margin="10" wrap-mode="1">
      <variable>DEBUG</variable>
      <input file>'$WORKDIR'/stderr</input>
    </edit>
    <variable>VBOX_DEBUG</variable>
  </hbox>



  <timer visible="false">
   <action>refresh:CMD</action>
   <action>refresh:CMD_COPY</action>
   <action>refresh:CMD_VISUALIZATION</action>
   <action>refresh:FFMPEG_OUT</action>
   <action>refresh:APLAY_OUT</action>
   <action>refresh:DEBUG</action>
  </timer>
 </vbox>
</window>
' | gtkdialog -s
